<?php
/**
 * 购物车列表
 * User: tengyu
 * Date: 2017/8/29
 * Time: 9:26
 */?>
@extends('common.common')
@section('title','购物车')
@section('css')<link rel="stylesheet" href="{{asset('/css/shoppingCar.css')}}">@endsection
@section('js')
    <script src="{{asset('/js/shoppingCar.js')}}"></script>
    <script>
        /**购物车操作-*/
        function decrecart(cartid,num)
        {
            if(num-1<1){
                common_deletecart(cartid);
            }else{
                num = num-1;
                common_cartedit(cartid,num);
            }
        }
        /**购物车操作+*/
        function increcart(cartid,num)
        {
            num = num+1;
            common_cartedit(cartid,num);
        }
        /**购物车删除*/
        function order_deletecart(id)
        {
            $.ajax({
                url:'/shopcart/delete/'+id,
                type:'post',
                headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                dataType:'json',
                success:function(res)
                {
                    if(res.res=='ok'){
                        alert(res.msg);
                        history.go(0);
                    }else{
                        alert(res.msg);
                    }
                }
            });
        }
        /**修改租赁方式*/
        function rentType_edit(id,type)
        {
            $.ajax({
                url:'/shopcart/edit/'+id,
                type:'post',
                headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                dataType:'json',
                data:{'id':id,'cart_rent_type':type},
                success:function(res){
                    if(res.res=='ok'){
                        history.go(0);
                    }else{
                        console.log(res);
                    }
                }
            });
        }
        /**加载样式选择*/
        function cart_fitment_dts(pid,dtid,cart_id)
        {
           $('.specifications').html('');
            $.ajax({
                url:'/shopcart/fitment_dts/'+pid,
                type:'get',
                data:{'cart_id':cart_id},
                dataType:'json',
                success:function(res){
                    if(res.res=='ok'){
                        var data = eval(res.data);
                        var html = '';
                        for(var i=0;i<data.length;i++){
                            html += '<p><b class="circle" onclick="repalce_fitment_dt('+res.cart_id+','+data[i].details_id+')"></b><span>';
                            html +=data[i].details_name+data[i].details_length+'*'+data[i].details_width+'M';
                            html +='</span></p>';
                        }
                        $('.specifications').append(html);
                    }else{
                        console.log(res.msg);
                    }
                }
            });
        }

        /**更换规格*/
        function repalce_fitment_dt(cart_id,dtid)
        {
            $.ajax({
                url:'/shopcart/edit/'+cart_id,
                type:'post',
                headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                data:{'id':cart_id,'dtid':dtid},
                dataType:'json',
                success:function(res)
                {
                    if(res.res=='ok'){
                        history.go(0);
                    }else{
                        console.log(res);
                    }
                }
            });
        }

        /**
         * 购物车选中详情，默认都选
         * checked.jpg 没选支付
         * choose.png 选择
         */
        function cart_dt_select(imgName,cart_id)
        {
            var cart_status = '';
            if(imgName=='checked.jpg'){
                 cart_status = '0';
            }else{
                cart_status = '1';
            }
            $.ajax({
                url:'/shopcart/edit/'+cart_id,
                type:'post',
                headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                data:{'id':cart_id,'cart_status':cart_status},
                dataType:'json',
                success:function(res)
                {
                    if(res.res=='ok'){
                        history.go(0);
                    }else{
                        console.log(res);
                    }
                }
            });
        }
        /**全选操作*/
        function shopcart_chooseAll()
        {
            $.ajax({
                url:'/shopcart/edit_status',
                type:'get',
                dataType:'json',
                data:{'status':'1'},
                success:function(res)
                {
                    if(res.res=='ok'){
                        history.go(0);
                        alert('请刷新!');
                    }else{
                        console.log(res);
                        history.go(0);
                    }
                }

            });
        }
    </script>
@endsection
@section('content')
    <div id="content">
        @include('common.centernav')
        <div class="container">
            <div id="panel" class="panel panel-default">
                <div class="panel-heading">
                    <h4>租赁清单</h4>
                </div>
                <div class="panel-body">
                    <ul class="product list-inline">
                        <li>商品信息</li>
                        <li>单价</li>
                        <li>数量</li>
                        <li>时长</li>
                        <li>操作</li>
                    </ul>
                    @foreach($param['cart']['cartlist'] as $v)
                    <ul class="orders list-inline">
                        <li class="imgInfo">
                            @if($v->cart_status==1)
                            <img class="selSingle" src="img/checked.jpg" onclick="cart_dt_select(this.alt,{{$v->cart_id}})" alt="checked.jpg">
                            @else
                            <img class="selSingle" src="img/choose.png" onclick="cart_dt_select(this.alt,{{$v->cart_id}})" alt="choose.png">
                            @endif
                            <div class="media">
                                <div class="media-left">
                                    <img src="{{asset(env('STATIC_FILE_ERP_PATH').$v->fitment_details_imgOne)}}" style="width:151px;height:92px;">
                                </div>
                                <div class="media-body">
                                    <p>{{$v->fitments_name}}</p>
                                    <p>
                                    <?php
                                    $color=DB::table('fitment_color')->where('color_details_id',$v->details_id)->select('color_type')->get();
                                    ?>
                                    @foreach($color as $key=>$value)
                                        <img src="{{$param['color'][$value->color_type]}}" alt="当前家具颜色">
                                    @endforeach
                                    </p>
                                    <p class="chooseSize">
                                        @if($v->cart_rent_type == 1)
                                        <span class="sui"><b>随租随还</b><i><</i></span>
                                        @else
                                        <span class="sui"><b>租满即送</b><i><</i></span>
                                        @endif
                                        <?php $cart_fitment_dt = \DB::table('fitment_details')->where('details_id',$v->details_id)->first();?>
                                        <span class="size" onclick="cart_fitment_dts({{$v->details_pid}},{{$v->details_id}},{{$v->cart_id}})">
                                            {{$cart_fitment_dt->details_name.$cart_fitment_dt->details_length*$cart_fitment_dt->details_height}}
                                        </span>
                                        <i class="yellow"><</i>
                                    </p>
                                    <div class="chooseWay">
                                        @if($v->cart_rent_type == 1)<p class="active">@else<p>@endif
                                            <span onclick="rentType_edit({{$v->cart_id}},1)">
                                            <b class="circle"></b>
                                            随租随还</span>
                                        </p>
                                        @if($v->cart_rent_type == 2)<p class="active">@else<p>@endif
                                            <span onclick="rentType_edit({{$v->cart_id}},2)">
                                            <b class="circle"></b>
                                           租满即送</span>
                                        </p>
                                    </div>
                                    <div class="specifications" dtid="{{$v->cart_id}}">
                                    @if(1>2)
                                    <p class="active"><b class="circle"></b><span>A型摆放两人位含柜1.2*2.8M</span></p>
                                    <p><b class="circle"></b><span>B型摆放两人位含柜1.2*2.8M</span></p>
                                    @endif
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li class="money">¥@if($v->cart_rent_type == 2){{$v->details_fixprice}}@else{{$v->details_nimbleprice}}@endif/月</li>
                        <li class="number">
                            <b class="glyphicon glyphicon-minus-sign" onclick="decrecart({{$v->cart_id}},{{$v->cart_fitment_num}})"></b>
                            <span class="num">{{$v->cart_fitment_num}}</span>
                            <b class="glyphicon glyphicon-plus-sign" onclick="increcart({{$v->cart_id}},{{$v->cart_fitment_num}})"></b>
                        </li>
                        <li class="selDate">
                            @if($v->cart_rent_type == 1)
                                <span class="active">12个月</span>
                            @else
                                <span class="active">18个月</span>
                            @endif
                        </li>
                        <li class="">
                            <span onclick="order_deletecart({{$v->cart_id}})">&times;</span>
                        </li>
                    </ul>
                    @endforeach
                </div>
                <div class="panel-footer">
                    <div class="leftaccount">
                        <ul class="list-inline">
                            <li>
                                <img src="/img/checked.jpg" alt="">
                            </li>
                            <li>
                                已选择<span>{{count($param['cart']['cartlist_status'])}}</span>件商品&nbsp;&nbsp;|&nbsp;&nbsp;<b id="chooseAll" onclick="shopcart_chooseAll()">全部选择</b>
                            </li>
                            <li class="rt">
                                应付信用额度:<i>¥{{$param['cart']['countcoupon']}}</i>
                            </li>
                            @if((string)$param['cart']['countprice']>0)
                                <li class="rt">
                                    应付押金租金:<i>¥{{$param['cart']['countbond']}}</i>
                                </li>
                            @endif
                            <li class="rt">
                                应付租金金额:<i>¥{{$param['cart']['countprice']}}</i>
                            </li>
                        </ul>
                        <p>
                            共计<span>{{$param['cart']['countnum']}}</span>件商品
                            <u class="rt">应付金额不包含运费</u>
                        </p>
                    </div>
                    <div class="rightaccount">
                        <b>
                            <i class="leftCircle"></i>
                            <a href="{{url('/confirmorder')}}">确认付款</a>
                            <i class="rightCircle"></i>
                        </b>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection